package org.bigtree.example.common.webapi;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bigtree.example.constans.ResponseCode;

/**
 * @author bigTree
 * @since 2025/4/24
 */
@Getter
@RequiredArgsConstructor
public class ResponseResult<T> {
    private final String code;
    private final String desc;
    private final T content;

    protected ResponseResult(IResponseCode respCode, T content) {
        this(respCode.code(), respCode.desc(), content);
    }

    protected ResponseResult(IResponseCode respCode) {
        this(respCode, null);
    }

    public static <R> ResponseResult<R> ok(R content) {
        return new ResponseResult<>(ResponseCode.OK, content);
    }

    public static ResponseResult<?> ok() {
        return new ResponseResult<>(ResponseCode.OK);
    }

    public static ResponseResult<?> fail(IResponseCode errCode) {
        return new ResponseResult<>(errCode);
    }
}
